//
//  LYQNameCardEditViewController.m
//  ZCProject
//
//  Created by 崔明燃 on 16/11/15.
//  Copyright © 2016年 Zheng. All rights reserved.
//

#import "LYQNameCardEditViewController.h"
#import "LYQNameCardEditCityViewController.h"

#import "LYQCardEditHeadImgTableViewCell.h"
#import "LYQCardEditNameTableViewCell.h"
#import "LYQCardEditPersonInfoTableViewCell.h"
#import "LYQTouristTipTableViewCell.h"
#import "LYQRightArrowsTableViewCell.h"

static NSString *personHeadImgCell = @"personHeadImgCell";  // 头像cell
static NSString *personNameCell = @"personNameCell";
static NSString *personInfoCell = @"personInfoCell";        // 个人信息cell
static NSString *travelTipCell = @"travelTipCell";          // 旅游标签cell
static NSString *companyInfoCell = @"companyInfoCell";      // 公司信息cell
static NSString *contentInfoCell = @"contentInfoCell";      // 联系方式cell
static NSString *businessNatureCell = @"businessNatureCell";


@interface LYQNameCardEditViewController ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation LYQNameCardEditViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"编辑名片";
    self.listTableView.delegate = self;
    self.listTableView.dataSource = self;
    
    [self.listTableView registerClass:[LYQCardEditHeadImgTableViewCell class] forCellReuseIdentifier:personHeadImgCell];
    [self.listTableView registerClass:[LYQCardEditNameTableViewCell class] forCellReuseIdentifier:personNameCell];
    [self.listTableView registerClass:[LYQCardEditPersonInfoTableViewCell class] forCellReuseIdentifier:personInfoCell];
    [self.listTableView registerClass:[LYQTouristTipTableViewCell class] forCellReuseIdentifier:travelTipCell];
    [self.listTableView registerClass:[LYQRightArrowsTableViewCell class] forCellReuseIdentifier:businessNatureCell];
}

#pragma mark - alert normal
- (void)alertShowWithMsg:(NSString *)titleStr {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:titleStr message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *takePicture = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    UIAlertAction *photo = [UIAlertAction actionWithTitle:@"从相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    UIAlertAction *actionCancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
    [alert addAction:takePicture];
    [alert addAction:photo];
    [alert addAction:actionCancle];
    
    [self presentViewController:alert animated:YES completion:nil];
}

#pragma mark - tableView delegate and datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 4;
    } else if (section == 1) {
        return 1;
    } else if (section == 2) {
        return 5;
    } else if (section == 3) {
        return 5;
    }
    return 0;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 40;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return .1f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 40;
    } else if (indexPath.section == 1) {
        return 80;
    } else if (indexPath.section == 2) {
        if (indexPath.row == 4) {
            return 100;
        }
    }
    return 40;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LYQCardEditHeadImgTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:personHeadImgCell];
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            LYQCardEditHeadImgTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:personHeadImgCell];
            
            return cell;
        } else if (indexPath.row == 1) {
            LYQCardEditNameTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:personNameCell];
            cell.titleLabel.text = @"姓名";
            cell.nameTextField.placeholder = @"李均";
            
            return cell;
        } else if (indexPath.row == 2) {
            LYQCardEditPersonInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:personInfoCell];
            cell.titleLabel.text = @"性别";
            cell.infoTextField.placeholder = @"男";
            return cell;
        } else if (indexPath.row == 3) {
            LYQCardEditPersonInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:personInfoCell];
            cell.titleLabel.text = @"城市";
            cell.infoTextField.text = @"北京";
            cell.infoTextField.enabled = NO;
            
            return cell;
        }
        else {
            LYQCardEditPersonInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:personInfoCell];
            
            return cell;
        }
    } 
    
    if (indexPath.section == 1) {
        LYQTouristTipTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:travelTipCell];
        
        return cell;
    }
    
    if (indexPath.section == 2) {
        if (indexPath.row == 2) {
            LYQRightArrowsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:businessNatureCell];
            
            cell.titleLabel.text = @"业务性质";
            
            return cell;
        } else if (indexPath.row == 4) {
            
        }
        
        LYQCardEditNameTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:personNameCell];
        
        if (indexPath.row == 0) {
            cell.titleLabel.text = @"公司";
            cell.nameTextField.placeholder = @"请输入公司名称";
            
            return cell;
        } else if (indexPath.row == 1) {
            cell.titleLabel.text = @"职务";
            cell.nameTextField.placeholder = @"请输入职务";
            
            return cell;
        } else if (indexPath.row == 3) {
            cell.titleLabel.text = @"详细地址";
            cell.nameTextField.placeholder = @"请输入详细地址";
        }
        
        return cell;
    } else if (indexPath.section == 3) {
        NSArray *titleArr = @[@"手机", @"电话", @"QQ", @"微信", @"邮箱"];
        LYQCardEditNameTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:personNameCell];
        cell.titleLabel.text = titleArr[indexPath.row];
        cell.nameTextField.placeholder = @"点击输入";
        return cell;
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            [self alertShowWithMsg:nil];
        } else if (indexPath.row == 3) {
            LYQNameCardEditCityViewController *cityVC = [[LYQNameCardEditCityViewController alloc] init];
            [self.navigationController pushViewController:cityVC animated:YES];
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
